function AllReady() {
    const mstform = Ext.getCmp("PayPlanPc");
    const dgrid1 = Ext.getCmp("PayPlanPcD")
    const dgrid2 = Ext.getCmp("PayPlanPcDD")

    //根据项目过滤合同
    //主表通用帮助过滤
    mstform
        .getItem("user_cnt_id")
        .on("beforetriggerclick", function (eOp, ignoreBeforeEvent) {
            return cntMFilter();
        });
    mstform
        .getItem("user_cnt_id")
        .on("helpselected", function (eOp, ignoreBeforeEvent) {
            getCntCz();
            getCntMInfoByPhid();
            getIncomeInspectionSum();
        });
    mstform
        .getItem("PhidPc")
        .on("helpselected", function (eOp, ignoreBeforeEvent) {
            getPcAccInfo();
            //获取合同数量
            getCntCount(() => {
                getCntCz();
                getCntMInfoByPhid();
                getIncomeInspectionSum();
            })
        });

    // 读取采购应付分析池的下推数据
    readXTData()
    function readXTData() {
        let json = localStorage.getItem("yffxc_to_prjectyc")
        if (!json) return
        json = JSON.parse(json)
        // 整理合计表体数据
        const total_row = []
        const rows = []
        let i_1 = 0
        for (let key in json) {
            i_1++
            const map = json[key]
            const temp = map.reduce((value, item) => {
                const el = { ...item }
                if (!mstform.getItem("user_tqjjfk").getValue()) {
                    mstform.getItem("user_tqjjfk").setValue(el.u_tqjjfk)
                }
                value.PhidSupplyEnt = String(el.u_supply)
                value.PhidSupplyEnt_EXName = el.u_supply_EXName
                value.ConNo = el.pcm_no
                value.PhidRecBank = el.u_rece_bank
                value.PhidRecBank_EXName = el.u_rece_bank_EXName
                value.RecBankAcc = el.u_bank_no
                value.RecAccName = el.u_payee_EXName
                value.ConName = el.u_cnt_name
                value.ConAmtFc = el.u_hthsje
                value.SortId = i_1
                // 全部累计本期到期日期
                value.ApvAmtFc = (Number(value.ApvAmtFc) || 0) + (Number(el.u_dqyfje) || 0)
                value.ApplyAmtFc = (Number(value.ApplyAmtFc) || 0) + (Number(el.u_dqyfje) || 0)
                value.PayableAmtFc = (Number(value.PayableAmtFc) || 0) + (Number(el.u_dqyfje) || 0)
                console.log(`项目检查`, mstform.getItem("PhidPc").getValue());
                if (!(Number(mstform.getItem("PhidPc").getValue()) || 0)) {
                    console.log(`项目id`, el.phid_pc);
                    mstform.getItem('PhidPc').setValue(el.phid_pc)
                    BatchBindCombox([mstform.getItem('PhidPc')])
                }
                return value
            }, {})
            total_row.push(temp)
        }
        // 整理全数据表体
        let i_2 = 0
        const rows_t = JSON.parse(localStorage.getItem("yffxc_to_prjectyc"))
        for (let key in rows_t) {
            const value = rows_t[key]
            value.forEach(el => {
                i_2++
                const els = {}
                els.PhidSupplyEnt = String(el.u_supply)
                els.PhidSupplyEnt_EXName = el.u_supply_EXName
                els.ConNo = el.pcm_no
                els.user_zftk = el.u_cnt_tklx,
                els.user_zftk_EXName = el.u_cnt_tklx_EXName,
                els.user_jsfs = el.u_zffs,
                els.user_cdqxsj = el.u_hp_dt,
                els.PhidRecBank = el.u_rece_bank
                els.PhidRecBank_EXName = el.u_rece_bank_EXName
                els.RecBankAcc = el.tick_taccountno_pcm
                els.RecAccName = el.u_payee_EXName
                els.ResourceType = '采购应付单'
                els.BillNo = el.u_yfdjh
                els.SortId = i_2
                // 全部累计本期到期日期
                els.ApvAmtFc = (Number(el.u_dqyfje) || 0)
                els.ApplyAmtFc = (Number(el.u_dqyfje) || 0)
                els.PayableAmtFc = (Number(el.u_dqyfje) || 0)
                els.PhidSourceid = el.u_yflx_phid
                rows.push(els)
            })
        }
        console.log(`debug整理数据`, total_row, rows);
        dgrid1.getStore().insert(0, total_row)
        dgrid2.getStore().insert(0, rows)
        localStorage.removeItem("yffxc_to_prjectyc")
    }

    function cntMFilter() {
        var PhidPc = mstform.getItem("PhidPc").getValue();
        if (!(Number(PhidPc) || 0)) {
            Ext.Msg.alert("提示", "请先选择项目！");
            mstform.getItem("PhidPc").focus();
            return false;
        } else {
            mstform.getItem("user_cnt_id").setOutFilter({
                phid_pc: PhidPc, //phid_pc 字段是通用帮助中的字段
                bill_type: 1,
            });
            return true;
        }
    }
    //获取合同产值
    function getCntCz() {
        if (!mstform.getItem("user_cnt_id").getValue()) return;
        console.log(mstform.getItem("user_cnt_id").getValue());
        execServer(
            "getCntCz",
            { phid_cnt: mstform.getItem("user_cnt_id").getValue() },
            (res) => {
                console.log(res);
                if (res.count == 0) return;
                const _data = JSON.parse(res.data)[0].extendObjects;
                console.log(_data);
                mstform.getItem("user_cnt_cz").setValue(_data.amt_sum);
            }
        );
    }

    function getCntMInfoByPhid() {
        // BatchBindCombox([user_regional_center])
        execServer(
            "getCntMInfoByPhid",
            { phid: mstform.getItem("user_cnt_id").getValue() },
            function (res) {
                const datas = JSON.parse(res.data)[0].extendObjects;
                console.log(datas);
                mstform.getItem("user_cnt_amt").setValue(datas.cnt_sum_vat_fc);
            }
        );
    }

    function getIncomeInspectionSum() {
        execServer(
            "getIncomeInspectionSum",
            { phid_pc: mstform.getItem("PhidPc").getValue() },
            function (res) {
                const datas = JSON.parse(res.data)[0].extendObjects;
                console.log(datas);
                mstform.getItem("user_cnt_srby").setValue(datas.u_by_amt);
            }
        );
    }
    function getPcAccInfo() {
        execServer(
            "getPcAccInfo",
            { phid_pc: mstform.getItem("PhidPc").getValue() },
            (res) => {
                console.log('获取内连账户信息', res);
                if (res.count == 0) return;
                const _data = JSON.parse(res.data)[0].extendObjects;
                const PhidInnerAcc = mstform.getItem("PhidInnerAcc");
                PhidInnerAcc.setValue(_data.phid_acc);
                BatchBindCombox([PhidInnerAcc]);
            }
        );
    }
    //获取合同数量
    getCntCount(() => {
        getCntCz();
        getCntMInfoByPhid();
        getIncomeInspectionSum();
    })
    function getCntCount(fun) {
        if (!mstform.getItem("PhidPc").getValue()) return
        execServer("getCntCount", { type: 1, phid_pc: mstform.getItem("PhidPc").getValue() }, (res) => {
            console.log(res, 'count');
            switch (res.count) {
                case 0:
                    return
                case 1:
                    const _data = JSON.parse(res.data)[0].extendObjects
                    mstform.getItem("user_cnt_id").setValue(_data.phid)
                    BatchBindCombox([mstform.getItem("user_cnt_id")])
                    setTimeout(() => {
                        if (fun) {
                            fun()
                        }
                    }, 200)
            }
        })
    }
}
